import 'package:flutter/material.dart';

class DataTablePage extends StatefulWidget {
  @override
  _DataTablePageState createState() => new _DataTablePageState();
}

class _DataTablePageState extends State<DataTablePage> {
  @override
  Widget build(BuildContext context) {
    final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey();

    return Scaffold(
      key: _scaffoldKey,
      appBar: AppBar(
        title: Text("DataTable"),
      ),
      body: _buildListView(),
    );
  }

  Widget _buildListView() {
    return ListView.builder(
      itemBuilder: (context, index) {
        return _buildListViewItem(index);
      },
      itemCount: dataTables.length,
    );
  }

  Widget _buildListViewItem(index) {
    return Container(
      padding: EdgeInsets.all(10.0),
      alignment: Alignment.center,
      child: dataTables[index],
    );
  }
}

List<Widget> dataTables = <Widget>[
  Column(
    children: <Widget>[
      Text("DataTable"),
      Container(
        child: SingleChildScrollView(
          scrollDirection: Axis.horizontal,
          child: DataTable(
            columns: [
              DataColumn(label: Text('姓名')),
              DataColumn(label: Text('年龄')),
              DataColumn(label: Text('年龄')),
              DataColumn(label: Text('年龄')),
              DataColumn(label: Text('年龄')),
            ],
            rows: [
              DataRow(onSelectChanged: (selected) {}, cells: [
                DataCell(Text('Gnerv')),
                DataCell(Text('18')),
                DataCell(Text('18')),
                DataCell(Text('18')),
                DataCell(Text('18')),
              ]),
              DataRow(onSelectChanged: (selected) {}, cells: [
                DataCell(Text('Gnerv')),
                DataCell(Text('18')),
                DataCell(Text('18')),
                DataCell(Text('18')),
                DataCell(Text('18')),
              ]),
            ],
          ),
        ),
      ),
    ],
  ),
];
